<script setup lang="ts">
import {ref} from 'vue'
import { setToken } from '@/utils/auth'
import { ElMessage } from 'element-plus'
const loginData =  ref({
    username: '',
    password: '',
    loginIP: ""
})

import { login, getInfo } from "@/api";
import router from '@/router';

//登录
const postLogin = () => {
    //always,always123
    //admin,123456
    if(!loginData.value.username){
        ElMessage.error('请输入用户名')
        return
    }
    if(!loginData.value.password){
        ElMessage.error('请输入密码')
        return
    }
    console.log(loginData)
    login(loginData.value).then(res => {
        console.log(res)
        if(res.code === 200){
            setToken(res.data)
            ElMessage({
                type: 'success',
                message: '登录成功',
            })
            router.replace({ path: '/index'})
        }
        else{
            ElMessage.error(res.msg)
        }
    })
}

</script>
<template>
    <div class="login_bg">
        <div class="login">
            <h1>数字化煤场平台</h1>
            <ul>
                <li>
                    <i><img src="../assets/img/ico_l1.png" alt=""></i>
                    <input type="text" v-model="loginData.username" placeholder="请输入账号" />
                </li>
                <li>
                    <i><img src="../assets/img/ico_l2.png" alt=""></i>
                    <input type="password" v-model="loginData.password" placeholder="请输入密码" />
                </li>
            </ul>
            <div class="remember">
                <input type="checkbox" name="remember" />
                记住密码
            </div>
            <button class="btn" @click="postLogin">立即登录</button>
        </div>
    </div>
</template>
<style scoped lang="scss">
.login_bg{
    background: url('../assets/img/login_bg1.jpg') no-repeat;
    background-size: cover;
    width: 100%;
    height: 100vh;
    .login{
        width: 672px;
        height: 423px;
        background: url('../assets/img/login_bg2.png') no-repeat;
        background-size: 100% 100%;
        position: absolute;
        left:50%;
        top:50%;
        transform: translate(-50%,-56%);
        h1{
            text-align: center;
            color:#91BAEA;
            font-size: 24px;
            line-height: 40px;
            font-weight: bold;
            padding: 25px 0;
        }
        ul{
            width: 400px;
            margin: 0 auto;
        }
        li{
            width: 400px;
            height: 40px;
            background: #294676;
            display: flex;
            align-items: stretch;
            justify-content: space-between;
            margin-top: 30px;
            i{
                flex-shrink: 0;
                width: 40px;
                height: 40px;
                display: flex;
                align-items: center;
                justify-content: center;
                background: #3966B1;
            }
            input{
                display: block;
                width: 100%;
                border:none;
                background: none;
                box-sizing: border-box;
                text-align: center;
                color: #fff;
                font-size: 18px;
                outline: none;
                &::placeholder{
                    color: #81A4DD;
                }
            }
        }
        .remember{
            display: flex;
            align-items: center;
            font-size: 16px;
            line-height: 20px;
            color: #A2CAF8;
            width: 400px;
            margin: 20px auto 0;
            input{
                
                display: block;
                border:none;
                background: #A2CAF8;
                margin-right: 5px;
            }
        }
        .btn{
            display: block;
            cursor: pointer;
            border:none;
            font-size: 20px;
            color: #FFFFFF;
            width: 400px;
            line-height: 46px;
            background: linear-gradient( 360deg, #2565C8 0%, #4E94FF 100%);
            width: 400px;
            margin: 40px auto 0;
        }
    }
}
</style>